< previous page page_359 next page >

Page 359
building tool in your application. Crystal Reports offers such a tool, although the version that ships with Visual Basic might be awkward. If you know at design time the tables from which the user will choose fields, you could present the user with some user-friendly list-views of the tables in the database and the fields in each table the user selects. Based on these selections, build a query and pass that query to either Access or Crystal Reports. For Crystal Reports, the syntax for setting the query of the active Crystal Reports control is
theCrystalControl.SQLQuery = SELECT SomeColumn FROM SomeTable . . .
where theCrystalControl is a reference to a current Crystal Reports control. You set this reference in the controller class that is responsible for the main reports form you implement. (ReportController for this lesson is the controller class you use.) For Access Reports objects, the syntax is
theAccessReport.RecordSource = SELECT SomeColumn FROM SomeTable . . .
where theAccessServer is an object of type Access.Report.
Modeling the Reporting and Printing Subsystem Object Model
Figure 16.2 shows the usual interactions of the objects in this subsystem. A user, represented as Report User, views the main form, frmReport, that has a list of reports the user can choose to open and print. Steps 1 and 2 represent this interaction. In step 3, the user gets a specific report by selecting the report in a list box and clicking some command button (let's call it cmdOpenReport). Step 4 is the method of the ReportController class that handles the cmdOpenReport_Click event. In step 5, ReportController invokes the openReport method of the IReporting class instance. In step 6, the IReporting class instance invokes the corresponding openReport method of its implementation class, ReportingClass, polymorphically. That is, when the openReport method of the IReporting class instance is invoked, the compiler routes the method call to the corresponding openReport method of the class that implements the IReporting interface. Steps 7 through 10 (printing the report) follow a similar pattern as the previous steps, but step 11 involves a call to the PrinterProxy object to do the actual printing. It's called PrinterProxy because it is a proxy, or stand-in, for the actual printer calls. Actually, within the PrinterProxy are calls to Visual Basic's Printer object, the Access Reports object's print methods, the Crystal Reports print methods, or the actual SelPrint method of the Rich Text Box control. The nice thing about having a PrinterProxy object is that regardless of how you actually use the printer functionality, you know to go to the PrinterProxy class when you encounter problems.

 
< previous page page_359 next page >

If you like this book, buy it!